home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / packer / xpkilzr / source / expand.c < prev    next >
C/C++ Source or Header  |  1996-02-26  |  3KB  |  129 lines

  1.  
  2.  
  3. /**-----------------------------------------------------------------------
  4.   *   Bloque de includes, por fin me ocupan menos de una pagina de
  5.   * impresisn, lo que hay que hacer para tener todos los prototipos..
  6.   *
  7.   **/
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13. #include <fcntl.h>
  14.  
  15. #define NO_SUB_PRAGMAS
  16. #include <libraries/xpksub.h>
  17.  
  18. #include "ilzr.h"
  19.  
  20. /**-----------------------------------------------------------------------
  21.   *   Prototipos para todas estas paridas necesarias para compilar.
  22.   *
  23.   **/
  24.  
  25. long __saveds __asm XpksUnpackChunk( REG __a0 XPARAMS* xpar )
  26. {
  27.     /*  variables para input - output   */
  28.   
  29. register  CHARS   *inpb;
  30. register  CHARS   *outb;
  31.           CHARS   *bumpcode;
  32.           CHARS   *outbstart;
  33.     signed long    outbsize;
  34.           ULONG    temp;
  35.     signed char    shift;
  36.           UBYTE    bitcount;
  37.           ULONG    matchpos;
  38.           ULONG    matchlen;      
  39.           
  40.  
  41.   inpb     = xpar->InBuf;
  42.   outb     = xpar->OutBuf;
  43.  
  44.   shift    = 0;
  45.   
  46.   outbstart= outb;
  47.   outbsize = *((unsigned short *)inpb);
  48.   inpb    += 2;     /* short leido */
  49.  
  50.   bitcount = INIT_BIT_BUMP;
  51.   bumpcode = &outb[ 1<<INIT_BIT_BUMP ]; 
  52.   
  53.   if( outbsize > xpar->OutBufLen )
  54.     return( XPKERR_SMALLBUF );
  55.   
  56.   xpar->OutBufLen = outbsize; 
  57.     
  58.   while( outbsize > 0 )
  59.     {
  60.     if( *inpb & (0x80>>shift) )
  61.       {
  62.       shift++;
  63.       if( shift > 7 )
  64.         {
  65.         shift=0;
  66.         inpb++;
  67.         }
  68.           
  69.         temp = ( ((ULONG *)inpb)[0]);
  70.         temp = ( temp>>(24-shift) );
  71.         *outb= (CHARS)( temp & 0xFF);
  72.         outb++;
  73.         inpb++;
  74.         outbsize--;
  75.         }
  76.       else
  77.         {
  78.         shift++;
  79.         if( shift > 7 )
  80.           {
  81.           shift=0;
  82.         inpb++;
  83.         }
  84.       
  85.       if( bumpcode <  outb )
  86.         {
  87.         bitcount++;
  88.         bumpcode = &outbstart[ 1<<bitcount ];
  89.         }
  90.  
  91.       temp     = ( ((ULONG *)inpb)[0]);
  92.       temp     = temp >> ( 32 - bitcount - shift );
  93.       matchpos = temp & ((1<<bitcount)-1);
  94.       
  95.       shift   += bitcount;    /* ALWAYS bitccount >= 8 */
  96.       shift   -=8;
  97.       inpb++;
  98.       if( shift > 7 )
  99.         {
  100.         shift-=8;
  101.         inpb++;
  102.         }
  103.       
  104.       temp     = ( ((ULONG *)inpb)[0]);
  105.       temp     = temp >> ( 32 - BITS_LOOKAHEAD - shift );
  106.       matchlen = temp & ((1<<BITS_LOOKAHEAD)-1);
  107.       
  108.       shift   += BITS_LOOKAHEAD;
  109.       if( shift > 7 )
  110.         {
  111.         shift-=8;
  112.         inpb++;
  113.         }
  114.         
  115.       matchlen += MIN_MATCH;
  116.       matchpos--;
  117.       for( temp = 0 ; temp < matchlen ; temp++ )
  118.         {
  119.         *outb=outbstart[ matchpos + temp ];
  120.         outb++;
  121.         }
  122.       outbsize -= matchlen;
  123.       }
  124.     }
  125.   return( 0 );
  126. }
  127.  
  128. /************************** End of ILZR.C *************************/
  129.